from Tkinter import *

from nipponsteel.gui.utils import FullMenu
from nipponsteel.gui.manager import ManagerProxy


class Menus(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)
        manager = self.manager = ManagerProxy(None)
        # FILE MENU
        self.file = FullMenu(self, name="File", tearoff=False)
        self.file.menu.add_command(label="Open", accelerator="Ctrl+o", command=manager.open)
        self.file.menu.add_command(label="Close", accelerator="Ctrl+w", command=manager.close)
        self.file.grid(row=0, column=0, sticky=N+S+W)
        # SIMULATION MENU
        self.sim = FullMenu(self, name="Simulation", tearoff=False)
        # ----
        speed_menu = Menu(tearoff=False)
        speed_menu.add_command(label="Up", accelerator="+", command=manager.speed_up)
        speed_menu.add_command(label="Down", accelerator="-", command=manager.speed_down)
        speed_menu.add_command(label="Reset", accelerator="0", command=manager.speed_reset)
        # ----
        zoom_menu = Menu(tearoff=False)
        zoom_menu.add_command(label="In", accelerator="Ctrl++", command=manager.zoom_in)
        zoom_menu.add_command(label="Out", accelerator="Ctrl+-", command=manager.zoom_out)
        zoom_menu.add_command(label="Reset", accelerator="Ctrl+0", command=manager.zoom_reset)
        # ----
        self.sim.menu.add_cascade(label="Speed", menu=speed_menu)
        self.sim.menu.add_cascade(label="Zoom", menu=zoom_menu)
        self.sim.menu.add_command(label="Refresh", accelerator="Ctrl+r", command=manager.refresh)
        self.sim.menu.add_separator()
        self.sim.menu.add_command(label="Rewind", accelerator="z", command=manager.rewind)
        self.sim.menu.add_command(label="Play back", accelerator="x", command=manager.play_back)
        self.sim.menu.add_command(label="Step back", accelerator="c", command=manager.step_back)
        self.sim.menu.add_command(label="Pause", accelerator="v", command=manager.pause)
        self.sim.menu.add_command(label="Step", accelerator="b", command=manager.step)
        self.sim.menu.add_command(label="Play", accelerator="n", command=manager.play)
        self.sim.menu.add_command(label="Forward", accelerator="m", command=manager.forward)
        self.sim.grid(row=0, column=1, sticky=N+S+W)
        # KEYBOARD SHORTCUT BINDINGS
        self.bind_all("<Control-KeyPress-o>", manager.open)
        self.bind_all("<Control-KeyPress-w>", manager.close)
        self.bind_all("<KeyPress-plus>", manager.speed_up)
        self.bind_all("<KeyPress-minus>", manager.speed_down)
        self.bind_all("<KeyPress-0>", manager.speed_reset)
        self.bind_all("<Control-KeyPress-plus>", manager.zoom_in)
        self.bind_all("<Control-KeyPress-minus>", manager.zoom_out)
        self.bind_all("<Control-KeyPress-0>", manager.zoom_reset)
        self.bind_all("<Control-KeyPress-r>", manager.refresh)
        self.bind_all("<KeyPress-z>", manager.rewind)
        self.bind_all("<KeyPress-x>", manager.play_back)
        self.bind_all("<KeyPress-c>", manager.step_back)
        self.bind_all("<KeyPress-v>", manager.pause)
        self.bind_all("<KeyPress-b>", manager.step)
        self.bind_all("<KeyPress-n>", manager.play)
        self.bind_all("<KeyPress-m>", manager.forward)
        
